package main

import (
	"fmt"
	"runtime"
)

var cha chan int

// channel初步练习
func main() {
	//查看运行系统中有几核cpu
	cpu := runtime.NumCPU()
	fmt.Println(cpu)
	//
	cha = make(chan int, 3)
	cha <- 22
	cha <- 99
	cha <- 66
	var length int = len(cha)
	var temp int
	for i := 0; i < length; i++ {
		temp = <-cha
		fmt.Printf("从管道中提取出数据%v", temp)
		fmt.Println()
	}
	//可以接收任何的数据类型
	var inter chan interface{} = make(chan interface{}, 3)
	inter <- 23.57
	inter <- 2222222222222222
	type dog struct {
		name string
	}
	var doo = dog{
		name: "mmmmmmmm",
	}
	inter <- doo
	//取出数据
	//前两个丢弃
	//<-inter
	//bbb := <-inter
	//fmt.Println(bbb)
	//sss := <-inter
	//fmt.Println(sss)
	//result := sss.(dog)
	//fmt.Println(result.name)
	close(inter)
	//遍历管道
	for v := range inter {
		fmt.Println(v)
	}

}
